package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.user.AddUserDTO;
import com.qk.dto.user.QueryPageUserDTO;
import com.qk.dto.user.UpdateUserDTO;
import com.qk.entity.User;
import com.qk.management.service.UserService;
import com.qk.vo.user.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:gzc
 * @Date: 2025/10/06 18:19
 * @Description:
 */
@RestController
@Slf4j
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping
    public Result queryListByPage(QueryPageUserDTO queryPageUserDTO) {
        log.info("用户分页查询参数：{}", queryPageUserDTO);
        PageResult<UserVO> queryListByPageVO = userService.queryListByPage(queryPageUserDTO);
        return Result.success(queryListByPageVO);
    }

    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable("ids") List<Integer> ids) {
        log.info("删除参数：{}", ids);
        userService.deleteByIds(ids);
        return Result.success();
    }

    @PostMapping
    public Result addUser(@RequestBody AddUserDTO addUserDTO) {
        log.info("新增参数：{}", addUserDTO);
        userService.addUser(addUserDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id) {
        log.info("查询参数：{}", id);
        User user = userService.queryById(id);
        return Result.success(user);
    }

    @PutMapping
    public Result updateById(@RequestBody UpdateUserDTO updateUserDTO) {
        log.info("修改参数：{}", updateUserDTO);
        userService.updateUser(updateUserDTO);
        return Result.success();
    }


    @GetMapping("/list")
    public Result queryAll() {
        log.info("查询所有用户信息");
        return  Result.success(userService.queryAll());
    }

    @GetMapping("/role/{roleLabel}")
    public Result queryByRole(@PathVariable String roleLabel) {
        return  Result.success(userService.queryByRole(roleLabel));
    }

    @GetMapping("/dept/{deptId}")
    public Result queryByDept(@PathVariable Integer deptId) {
        return  Result.success(userService.queryByDept(deptId));
    }
}
